package de.ret_world.openrpgstudio.editor.gui;

import buoy.widget.CustomWidget;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;

/**
 * A Widget for displaying a RSyntaxTextArea for lua code. You can use this in your plugins to show a syntax highlighted TextArea.
 *
 * @author Emu
 */
public class ScriptArea extends CustomWidget {

    private RTextScrollPane scrl;
    private RSyntaxTextArea txtSA;

    /**
     * Creates a new empty ScriptArea with Lua syntax highlighting.
     */
    public ScriptArea() {
        txtSA = new RSyntaxTextArea();
        txtSA.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LUA);
        txtSA.setLineWrap(true);
        txtSA.setWrapStyleWord(true);

        scrl = new RTextScrollPane(txtSA);

        component = scrl;
    }

    /**
     * Creates a new ScriptArea with Lua syntax highlighting
     * @param text the text to show in the ScriptArea
     */
    public ScriptArea(String text) {
        this();
        txtSA.setText(text);
    }
    
    /**
     * @param text the text to show in the ScriptArea
     */
    public void setText(String text) {
        txtSA.setText(text);
    }
    
    /**
     * @return the text inside the ScriptArea
     */
    public String getText() {
        return txtSA.getText();
    }
    
    /**
     * @param editable set the ScriptArea editable or not
     */
    public void setEditable(boolean editable) {
        txtSA.setEditable(editable);
    }
    
    /**
     * @return true if the ScriptArea is editable, false if not
     */
    public boolean isEditable() {
        return txtSA.isEditable();
    }

    @Override
    public void setEnabled(boolean enabled) {
        txtSA.setEnabled(enabled);
    }
}
